﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using AMS.Chess.CommonLayer;

namespace AMS.Chess.Test
{
    public class TestChessPieceFactory : IChessPieceFactory
    {
        public TestChessPieceFactory() { }

        public virtual APawn CreatePawn(AChessBoard board, ChessColor color)
        {
            return new TestPawn(board, color);
        }

        public virtual AKnight CreateKnight(AChessBoard board, ChessColor color)
        {
            return new TestKnight(board, color);
        }

        public virtual ABishop CreateBishop(AChessBoard board, ChessColor color)
        {
            return new TestBishop(board, color);
        }

        public virtual ARook CreateRook(AChessBoard board, ChessColor color)
        {
            return new TestRook(board, color);
        }

        public virtual AQueen CreateQueen(AChessBoard board, ChessColor color)
        {
            return new TestQueen(board, color);
        }

        public virtual AKing CreateKing(AChessBoard board, ChessColor color)
        {
            return new TestKing(board, color);
        }
        
        /// <summary>
        /// Provides extensibility to allow a subclassed factory to produce other types of pieces.
        /// </summary>
        /// <param name="t"></param>
        /// <returns></returns>
        public virtual AChessPiece CreateChessPiece(Type t, AChessBoard board, ChessColor color)
        {
            if (t == typeof(TestKing)) { return CreateKing(board, color); }
            else if (t == typeof(TestQueen)) { return CreateQueen(board, color); }
            else if (t == typeof(TestRook)) { return CreateRook(board, color); }
            else if (t == typeof(TestBishop)) { return CreateBishop(board, color); }
            else if (t == typeof(TestKnight)) { return CreateKnight(board, color); }
            else if (t == typeof(TestPawn)) { return CreatePawn(board, color); }
            else
            {
                //return null;
                throw new InvalidOperationException("This Factory cannot produce the specified Type of AChessPiece.");
            }
        }
    }
}
